package com.gigi.searchcenterbackendmaster.model.dto;

import cn.hutool.core.bean.BeanUtil;
import com.gigi.searchcenterbackendmaster.model.entity.UserEntity;
import io.github.classgraph.json.Id;
import lombok.Data;
import org.springframework.data.elasticsearch.annotations.Document;

import java.util.Objects;

/**
 * 用于接收 ES 中用户数据的 DTO
 *
 * @author Gigi
 * @date 2024/8/20 19:02
 */
@Document(indexName = "user")
@Data
public class UserEsDTO {

    @Id
    private Long id;

    private String avatarUrl;

    private String userName;

    private String intro;

    private Integer ifDelete;

    /**
     * 将实体类转换为 DTO
     *
     * @param userEntity
     * @return
     */
    public static UserEsDTO entityToDTO(UserEntity userEntity) {
        if (Objects.isNull(userEntity)) {
            return null;
        }
        UserEsDTO userEsDTO = new UserEsDTO();
        BeanUtil.copyProperties(userEntity, userEsDTO);
        return userEsDTO;
    }

}
